﻿using System;
using System.Threading;
using System.Threading.Tasks;

namespace PubSub.S2
{
    public class Level2
    {
        public static void Test()
        {
            try
            {
                RedisPubSubProvider.Subscribe(new BaseHandler1());
                RedisPubSubProvider.Subscribe(new BaseHandler2());

                Task.Run(() =>
                {
                    while (true)
                    {
                        Thread.Sleep(1000);
                        var pubMessage = new RedisPubSubMessage()
                        {
                            FuncType = FuncTypeEnum.Test1,
                            SiteKey = "erp60",
                            CreateTime = DateTime.Now.ToShortTimeString(),
                            PayLoad = new
                            {
                                A = 1,
                                B = "2",
                                C = DateTime.Now
                            }
                        };
                        RedisPubSubProvider.Publish(pubMessage);
                        
                        
                        Thread.Sleep(1000);
                        var pubMessage2 = new RedisPubSubMessage()
                        {
                            FuncType = FuncTypeEnum.Test2,
                            SiteKey = "erp60-cost",
                            CreateTime = DateTime.Now.ToShortTimeString(),
                            PayLoad = new
                            {
                                A = 1,
                                B = "2",
                                C = DateTime.Now
                            }
                        };
                        RedisPubSubProvider.Publish(pubMessage2);
                    }
                });
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
                throw;
            }
        }
    }
}